package run;

import java.io.File;
import java.util.ArrayList;
import vkmc.Settings;

public class LanguageLoader
{
	public static ArrayList<LanguageFile> langs;
	private static ArrayList<String> langNames;
	
	public static LanguageFile currentLang;
	
	public static void loadLanguages()
	{
		langs = new ArrayList<LanguageFile>();
		langNames = new ArrayList<String>();
		
		File dir = new File("lang");
		String[] list = dir.list();
		for (String l : list)
		{
			LanguageFile lf = new LanguageFile("lang/" + l);
			langNames.add(lf.getName());
			langs.add(lf);
		}
		
		if (langs.size() == 0)
		{
			MsgBox.show("No language files found");
			System.exit(1);
		}
		
		setCurrentLanguage(Settings.getLanguage());
	}
	
	public static String[] getLanguageNames()
	{
		String[] names = new String[langNames.size()];
		int i = 0;
		for (String s : langNames)
		{
			names[i] = s;
			i++;
		}
		return names;
	}
	
	public static LanguageFile getLanguageByName(String name)
	{
		for (int i = 0; i < langNames.size(); i++)
		{
			String s = langNames.get(i);
			if (name.equals(s))
				return langs.get(i);
		}
		return langs.get(0);
	}
	
	public static void setCurrentLanguage(String name)
	{
		currentLang = getLanguageByName(name);
	}
}
